package org.liaohailong.library.widget.shopping.adapter;

import androidx.annotation.NonNull;

import org.liaohailong.library.widget.shopping.layout.ShoppingLayoutManager;
import org.liaohailong.library.widget.shopping.observable.IDataObservable;
import org.liaohailong.library.widget.shopping.observable.IShoppingDataObserver;

/**
 * Author: Victor
 * E-mail: liaohailong190@foxmail.com
 * Date: 2019/6/22 15:12
 * Description: 局部布局
 */
public abstract class ShoppingSectionAdapter<VH extends ShoppingViewHolder> implements IShoppingAdapter<VH>, IDataObservable {

    private IShoppingDataObserver dataObserver;

    /**
     * 获取布局器
     *
     * @return 列表布局器
     */
    public abstract ShoppingLayoutManager getLayoutManager();

    @NonNull
    @Override
    public ShoppingItemViewType getItemViewType(int position) {
        return new ShoppingItemViewType(position, ShoppingItemViewType.DEFAULT_VIEW_TYPE);
    }

    @Override
    public void setDataObserver(IShoppingDataObserver observer) {
        dataObserver = observer;
    }

    @Override
    public IShoppingDataObserver getDataObserver() {
        return dataObserver;
    }

    @Override
    public void notifyDataSetChanged() {
        getDataObserver().onItemRangeChanged(0, getItemCount());
    }

    @Override
    public void notifyItemRangeChanged(int position, int count) {
        getDataObserver().onItemRangeChanged(position, count);
    }

    @Override
    public void notifyItemRangeInserted(int position, int count) {
        getDataObserver().onItemRangeInserted(position, count);
    }

    @Override
    public void notifyItemRangeRemoved(int position, int count) {
        getDataObserver().onItemRangeRemoved(position, count);
    }
}
